#include <tap.h>
#include "../vcd-util.h"
#include "../vcd-conf/vcd-conf.h"
#include "../vcd-log.h"

//use this test should download libtap from github.com
//download url:https://github.com/zorgnax/libtap

//gcc -ggdb3 -o test_vcd_conf test_vcd_conf.c ../vcd-conf/vcd-conf.c ../vcd-log.c  -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -lglib-2.0 -ltap

int main (int argc, char* argv) 
{
	log_init();
	
	int res = read_vcd_conf();


    struct vcd_conf* f =  g_vcd_conf;
    plan(5);

    ok(f->login_mode == EMODE_OLD, "login mode is EMODE_OLD");

    res = strcmp(f->ip, "192.168.10.221");
    ok(res == 0, "ip is 192.168.10.221 ");

    res = strcmp(f->username, "root@pam");
    ok(res == 0, "username is root@pam");

    res = strcmp(f->node, "n207");
    ok(res == 0, "node is n207");

    ok(f->vmid, "vmid is 101");

    res = strcmp(f->public_id, "");
    ok(res == 0, "public-id is empty");

    ok(f->bitrate == 4, "bitrate is 4");

    res = strcmp(f->passwd, "rcCfvgT8Sq+SxkEIRqsOEg==\n");
    ok(res == 0, "passwd is rcCfvgT8Sq+SxkEIRqsOEg==\n");


    ok(f->enable_user_passwd == 1, "if-enable-user-passwd is ENABLE");

    ok(f->login_way == PRIVATE_LOGIN, "login-way is PRIVATE");

    ok(f->enable_grade == 1, "if-enable-grade is ENABLE");


    res = strcmp(f->sys_passwd, "");
    ok(res == 0, "sys-passwd is empty");

    ok(f->enable_autologin == 0, "if-autologin is NO");


    f->bitrate = 3;
    res = update_vcd_conf();
    ok(res == 0 ,"update_vcd_conf is ok");

    res=reload_vcd_conf();
    ok(f->bitrate, "bitrate is 3");

    f->bitrate = 4;
    res = update_vcd_conf();


    return 0;

    int bronze = 1, silver = 2, gold = 3;
    ok(bronze < silver, "bronze is less than silver");
    ok(bronze > silver, "not quite");
    is("gold", "gold", "gold is gold");
    cmp_ok(silver, "<", gold, "%d <= %d", silver, gold);
    like("platinum", ".*inum", "platinum matches .*inum");
    done_testing();
}


/*

1..5
ok 1 - login mode is EMODE_OLD
ok 2 - ip is 192.168.10.221
ok 3 - username is root@pam
ok 4 - node is n207
ok 5 - vmid is 101
ok 6 - public-id is empty
ok 7 - passwd is rcCfvgT8Sq+SxkEIRqsOEg==

ok 8 - if-enable-user-passwd is ENABLE
ok 9 - login-way is PRIVATE
ok 10 - if-enable-grade is ENABLE
ok 11 - sys-passwd is empty
ok 12 - if-autologin is NO
ok 13 - update_vcd_conf is ok
*/
